package com.exam.user.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Autowired
    private StringRedisTemplate redisTemplate;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession();
        Object loginuser=session.getAttribute("loginuser");
/*        Map<Object,Object> map=redisTemplate.opsForHash().entries("login");
        Object loginuser=map.get("username");*/
        if(loginuser==null){
            request.setAttribute("msg","请输入用户名及密码");
            request.getRequestDispatcher("/").forward(request,response);
            return  false;
        }
        return true;

    }
}
